<template>
  <div class="layui-layout layui-layout-admin">
    <div class="adminnav1">
      <Pagetop></Pagetop>
    </div>
    <div class="adminnav2">
      <Secondnav urlname="shoppv"></Secondnav>
    </div>

    <!-- 主体内容 -->
    <div class="layui-body kedou-admin" id="LAY_app_body app">
      <div class="layadmin-tabsbody-item layui-show">
        <div class="pagelist">

          <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title">
              <li class="layui-this" @click='getdate("COMMODITY")'>商品PV总值设置</li>
              <li @click='getdate("UNIFIED")'>PV总值统一设置</li>
              <li @click='getdate("PVli")' v-if="type==1">分享PV统一设置</li>
            </ul>
            <div class="layui-tab-content" style="padding:50px 0;font-size:14px">
              <div class="layui-tab-item layui-show">
                <div class="pagetop">
                  <Search :seadate="searchArr"></Search>
                </div>
                <div class="layui-card-body">
                  <div class="buttop">
              <button type="button" class="layui-btn layui-btn-normal" @click="shopset">现金商城</button>
              <button type="button" class="layui-btn layui-btn-warm" @click="ucset">UC商城</button>
            </div>
                  <Tables
                    :fdate="pdate"
                    :result="res"
                    height="430"
                    :totalCount="totalRows"
                    :pageNumber="curindex"
                    :fbtn="btn"
                  ></Tables>
                </div>
              </div>
              <div class="layui-tab-item" style="font-size:14px">
                <div class="layui-form" lay-filter>
                  <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">PV分润总值</label>
                <div class="layui-input-inline">
                  <input
                    type="text"
                    name
                    v-model="set[0].amountlimit"
                    placeholder
                    autocomplete="off"
                    class="layui-input"
                  />
                </div>
                <div class="layui-form-mid">%</div>
                <div class="layui-form-mid layui-word-aux">PV分润比例,如10表示10%</div>
              </div>
            </div>

                </div>
                <div class="layui-form-item" style="margin-left:10%;margin-top:20px;">
                  <button class="layui-btn" @click="sure()">保存设置</button>
                </div>
              </div>

               <div class="layui-tab-item">
                   <div class="layui-form" lay-filter>
                  <div style="padding: 20px; background-color: #F2F2F2;">
                    <div class="layui-row layui-col-space15">
                      <div
                        class="layui-col-md12"
                        v-for="(item,index) in roleTypelist"
                        :value="item.id"
                        :key="index"
                      >
                        <div class="layui-card">
                          <div class="layui-card-body">
                            <div class="layui-form-item">
                              <div class="layui-card-header">{{item.aliasName}}</div>
                            </div>

                            <div class="layui-form-item">
                              <div class="layui-inline">
                                <label class="layui-form-label">经营者</label>
                                <div class="layui-inline">
                                  <div class="layui-input-inline">
                                    <input
                                      type="text"
                                      v-model="dealerIntroducerRofit[index]"
                                      lay-verify="dealerIntroducerRofit"
                                      autocomplete="off"
                                      disabled="disabled"
                                      class="layui-input"
                                    />
                                  </div>
                                  <div class="layui-form-mid">%</div>
                                  <div class="layui-form-mid layui-word-aux">直推分润比例,如10表示10%</div>
                                </div>
                              </div>
                            </div>

                            <div class="layui-form-item">
                              <div class="layui-inline">
                                <label class="layui-form-label">消费者</label>
                                <div class="layui-input-inline">
                                  <select :name="'rofitType'+index" :lay-filter="'rofitnum'+index" disabled="disabled">
                                    <option value="">请选择</option>
                                    <option
                                      v-for="(its,indexss) in rofitlist"
                                      :selected="its.id==rofitTypeList[index]"
                                      :value="its.id"
                                      :key="indexss"
                                    >{{its.name}}</option>
                                  </select>
                                </div>
                              </div>
                              <div class="layui-inline">
                                <div class="layui-input-inline">
                                  <input
                                    type="text"
                                    required
                                    v-model="consumerRelateRofit[index]"
                                    lay-verify="consumerRelateRofit"
                                    autocomplete="off"
                                    disabled="disabled"
                                    class="layui-input"
                                  />
                                </div>
                                <div class="layui-form-mid">%</div>
                                  <div class="layui-form-mid layui-word-aux">分润比例,如10表示10%</div>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>

              </div>

            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Pagetop from "../common/pagetop.vue";
import Secondnav from "../common/secondnav.vue";
import Tables from "../common/tables.vue";
import Search from "../common/search.vue";
export default {
  name: "shoppvlist",
  components: { Pagetop, Secondnav, Tables, Search },
  data() {
    return {
      pdate: [], //表头
      res: "", //内容
      totalRows: "", //总数量
      curindex: 1, //页数
      btn: [], //按钮
      searchArr: [], //搜索
      isShow: false,
      seapram: "",
       idlist: [],
      rofitType: {
        id: "",
      },
      roleType: {
        id: "",
      },
      dealerIntroducerRofit: [],
      consumerRelateRofit: [],
      rofitTypeList: [],
      type: localStorage.getItem("type"),
      rofitlist: [], //分润类型
      roleTypelist: [
        {
          id: "",
          name: "",
          aliasName: "",
        },
      ], //角色类型
      
     set:[{
        amountlimit:"",
        id:"",
     }]
        

    };
  },
  mounted() {
    layui.use("element", function () {
      var element = layui.element;
    });
    this.getdate("COMMODITY");
    this.getsearch();
    this.getrofit();
    this.getroleType();
  },
  methods: {
    getdate: function (type) {
      var _this = this;
      var url = "/profit/bapi/v1.9/platformp-rofit";
      if (type == "UNIFIED") {
        url = "/profit/bapi/v1.9/platformp-rofit" + "?settingType.in=UNIFIED&dealerId.in=-1&page=0";
        ajaxRequest(url, "GET", "json", "", function (ret, err) {
          if(ret.data.list.length>0){
          _this.set  = ret.data.list
          }
        });
        } else if(type == "PVli"){
            var purl = "/profit/papi/v1.9/rofitpv";
            ajaxRequest(purl, "GET", "json", "", function (ret, err) {
              if (ret.data.list.length > 0) {
            var arr = ret.data.list;
            for (var i = 0; i < arr.length; i++) {
              _this.rofitTypeList.push(arr[i].rofitType.id) 
              _this.dealerIntroducerRofit.push(arr[i].dealerIntroducerRofit)
              _this.consumerRelateRofit.push(arr[i].consumerRelateRofit)
              _this.idlist.push(arr[i].id);
            }
          }
                
        });
        } else {
        if (_this.seapram) {
          var dates = {
            size: pageSize,
            page: _this.curindex,
            sort: "createAt,DESC",
            "settingType.in": "COMMODITY",
          };
          var res = _this.seapram;
          for (var i = 0; i < res.length; i++) {
            dates[res[i].key + ".equals"] = res[i].val;
          }
        } else {
          var dates = {
            size: pageSize,
            page: _this.curindex,
            sort: "createAt,DESC",
            "settingType.in": "COMMODITY",
          };
        }
        ajaxRequest(url, "GET", "json", dates, function (ret, err) {
          var arr = [];
          arr[0] = [
            { field: "id", title: "ID" },
            { field: "commodityName", title: "商品名称" },
            {
              field: "commodityLogo",
              title: "商品图片",
              templet:
                '<div><img src="{{d.commodityLogo}}" style="display: inline-block; height: 100%;"></div>',
            },
            { field: "amountlimit", title: "设置pv分润总值比例(%)" },
            {
              field: "mallType",
              title: "商品类型",
              templet: function (d) {
                if (d.mallType == 1) return "现金商城";
                else return "UC商城";
              },
            },
            {            field: "createAt", title: "创建日期", templet: function (d) {
              return FormatDate(d.createAt, 3);
            }          },
            {
              field: "right",
              title: "操作",
              width:"100",
              fixed: "right",
              templet: function (d) {
                var str =
                  '<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">编辑</a>';
                return str;
              },
            },
          ];
          _this.pdate = arr;
          _this.res = ret.data.list;
          _this.totalRows = ret.data.totalRows;
          _this.curindex = ret.data.page + 1;
        });
      }
    },
    getsearch: function () {
      var arr = [{ field: "id", title: "ID", type: "input" }];
      this.searchArr = arr;
    },
    page: function (index, obj) {
      //alert(JSON,stringify(obj))
      this.curindex = index;
      this.getdate();
    },
    sousuo: function (pram) {
      //alert(JSON.stringify(pram))
      this.seapram = pram;
      this.res = "";
      this.totalRows = "";
      this.curindex = "";
      this.getdate();
    },
    sure: function () {
      var _this = this;
      var url = '/profit/bapi/v1.9/platformp-rofit';
      if(_this.set[0].id){
        var hat = "PUT"
      var dates = {
        amountlimit: _this.set[0].amountlimit,
        settingType:"UNIFIED",
        id:_this.set[0].id
      }
      }else{
        var hat = "POST"
        var dates = {
        amountlimit: _this.set[0].amountlimit,
        settingType:"UNIFIED",
      }
      }
      ajaxRequest(url, hat, 'json', dates, function (ret, err) {
        layer.msg('设置成功');
        setTimeout(function () {
          var index = parent.layer.getFrameIndex(window.name);
          parent.layer.close(index);
            parent.location.reload();
        }, 1000);
      })
    },
    shopset: function () {
      var _this = this;
      layer.open({
        type: 2,
        title: "选择商城类型",
        content: baseurl + "/shoppvadd",
        area: ["90%", "80%"],
      });
    },
    ucset: function () {
      var _this = this;
      layer.open({
        type: 2,
        title: "选择商城类型",
        content: baseurl + "/ucshoppvadd",
        area: ["90%", "80%"],
      });
    },
    editInfo: function (data) {
      var _this = this;
      layer.open({
        type: 2,
        title: "编辑商品PV总值分润比例",
        content: baseurl + "/shoptype",
        area: _this.screens() < 2 ? ["65%", "25%"] : ["650px", "250px"],
        success: function (layero, index) {
          var iframeWin = window[layero.find("iframe")[0]["name"]];
          iframeWin.getdates(data);
        },
      });
    },
     getrofit: function () {
      var _this = this;
      var url = "/profit/papi/v1.9/rofit-type/";
      ajaxRequest(url, "GET", "json", "", function (ret, err) {
        _this.rofitlist = ret.data;
        // alert(JSON.stringify(_this.rofitlist))
      });
    },
    getroleType: function () {
      var _this = this;
      var url = "/profit/papi/v1.9/role-type";
      ajaxRequest(url, "GET", "json", "", function (ret, err) {
        _this.roleTypelist = ret.data;
        // alert(JSON.stringify(_this.roleTypelist))
      });
    },
    screens: function () {
      return screen();
    },
  },
  updated: function () {
    this.isShow = true;
    layui.use("form", function () {
      var form = layui.form;
      form.render();
     form.on("select(rofitnum0)", function (data) {
        _this.rofitTypeList[0] = data.value;
      });
      form.on("select(rofitnum1)", function (data) {
        _this.rofitTypeList[1] = data.value;
      });
      form.on("select(rofitnum2)", function (data) {
        _this.rofitTypeList[2] = data.value;
      });
      form.on("select(rofitnum3)", function (data) {
        _this.rofitTypeList[3] = data.value;
      });
      form.on("select(rofitnum4)", function (data) {
        _this.rofitTypeList[4] = data.value;
      });
      form.on("select(rofitnum5)", function (data) {
        _this.rofitTypeList[5] = data.value;
      });
      form.on("select(rofitnum6)", function (data) {
        _this.rofitTypeList[6] = data.value;
      });
      form.on("select(rofitnum7)", function (data) {
        _this.rofitTypeList[7] = data.value;
      });
      form.on("select(rofitnum8)", function (data) {
        _this.rofitTypeList[8] = data.value;
      });
      form.on("select(rofitnum9)", function (data) {
        _this.rofitTypeList[9] = data.value;
      });
      form.on("select(rofitnum10)", function (data) {
        _this.rofitTypeList[10] = data.value;
      });
      form.on("select(rofitnum11)", function (data) {
        _this.rofitTypeList[11] = data.value;
      });
      form.on("select(rofitnum12)", function (data) {
        _this.rofitTypeList[12] = data.value;
      });
      form.on("select(rofitnum13)", function (data) {
        _this.rofitTypeList[13] = data.value;
      });
      form.on("select(rofitnum14)", function (data) {
        _this.rofitTypeList[14] = data.value;
      });
      form.on("select(rofitnum15)", function (data) {
        _this.rofitTypeList[15] = data.value;
      });
      form.on("select(rofitnum16)", function (data) {
        _this.rofitTypeList[16] = data.value;
      });
      form.on("select(rofitnum17)", function (data) {
        _this.rofitTypeList[17] = data.value;
      });
      form.on("select(rofitnum18)", function (data) {
        _this.rofitTypeList[18] = data.value;
      });
      form.on("select(rofitnum19)", function (data) {
        _this.rofitTypeList[19] = data.value;
      });
      form.on("select(rofitnum20)", function (data) {
        _this.rofitTypeList[20] = data.value;
      });
    });
  },
};
</script>
<style scoped>
/**/
</style>